package com.cloudkinto.controller.operate;


import com.cloudkinto.common.annotations.UserSessionRequired;
import com.cloudkinto.common.web.PageResult;
import com.cloudkinto.enumType.operate.OperateTypeEnum;
import com.cloudkinto.base.BaseController;
import com.cloudkinto.common.web.SingleResult;
import com.cloudkinto.service.operate.OperateRecordService;
import com.cloudkinto.vo.operate.OperateRes;
import io.swagger.annotations.*;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author hua
 * @since 2023-11-20
 */
@RestController
@Api(tags = "操作日志模块")
@RequestMapping("/api/admin/OperateRecord")
@RequiredArgsConstructor
public class OperateRecordController extends BaseController {
    private final OperateRecordService operateRecordService;

    @UserSessionRequired
    @GetMapping("/getStockToPlatformRecord")
    @ApiOperation(value = "获取库存回传日志")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "beginTime", value = "开始时间"),
            @ApiImplicitParam(name = "endTime", value = "结束时间"),
            @ApiImplicitParam(name = "current", value = "当前页"),
            @ApiImplicitParam(name = "pageSize", value = "页面大小"),
            @ApiImplicitParam(name = "platformSku", value = "平台sku")
    })
    @ApiResponses(@ApiResponse(code = 200, message = "", response = OperateRes.class))
    public PageResult getStockToPlatformRecord(HttpServletRequest request) {
        Map<String, Object> map = new HashMap<>();
        map.put("beginTime", request.getParameter("beginTime"));
        map.put("endTime", request.getParameter("endTime"));
        String current = request.getParameter("current");
        String size = request.getParameter("pageSize");
        map.put("current", current);
        map.put("pageSize", size);
        map.put("platformSku", request.getParameter("platformSku"));
        return operateRecordService.getStockToPlatformRecord(map);
    }


    @UserSessionRequired
    @GetMapping("/getPlatformProductOperateList")
    @ApiOperation(value = "获产品映射操作日志")
    @ApiResponses(@ApiResponse(code = 200, message = "", response = OperateRes.class))
    public SingleResult getPlatformProductOperateList(@RequestParam("thirdId") Long thirdId) {
        return SingleResult.success(operateRecordService.getOperateList(thirdId, OperateTypeEnum.PlatProduct));
    }

    @UserSessionRequired
    @GetMapping("/getPlatformOperateList")
    @ApiOperation(value = "获取EC订单操作日志")
    @ApiResponses(@ApiResponse(code = 200, message = "", response = OperateRes.class))
    public SingleResult getPlatformOperateList(@RequestParam("thirdId") Long thirdId) {
        return SingleResult.success(operateRecordService.getOperateList(thirdId, OperateTypeEnum.PlatformOrder));
    }

    @UserSessionRequired
    @GetMapping("/getInputOperateList")
    @ApiOperation(value = "获取入库单操作日志")
    public SingleResult getOperateByThirdId(@RequestParam("thirdId") Long thirdId) {
        return SingleResult.success(operateRecordService.getOperateList(thirdId, OperateTypeEnum.OrderInput));
    }

    @UserSessionRequired
    @GetMapping("/getShelfOperateList")
    @ApiOperation(value = "获取上架单操作日志")
    public SingleResult getShelfOperateListByThirdId(@RequestParam("thirdId") Long thirdId) {
        return SingleResult.success(operateRecordService.getOperateList(thirdId, OperateTypeEnum.Shelf));
    }

    @UserSessionRequired
    @GetMapping("/getOutboundOperateList")
    @ApiOperation(value = "获取出库单操作日志")
    public SingleResult getOutboundOperateListByThirdId(@RequestParam("thirdId") Long thirdId) {
        return SingleResult.success(operateRecordService.getOperateList(thirdId, OperateTypeEnum.OrderOutbound));
    }

    @UserSessionRequired
    @GetMapping("/getWaveOperateList")
    @ApiOperation(value = "获取波次操作日志")
    public SingleResult getWaveOperateListByThirdId(@RequestParam("thirdId") Long thirdId) {
        return SingleResult.success(operateRecordService.getOperateList(thirdId, OperateTypeEnum.Wave));
    }
}

